package com.dmitrik.Sensors;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import kankan.wheel.widget.OnWheelChangedListener;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.ArrayWheelAdapter;

public class FrontendActivity extends Activity {

    private int currActivity = -1;
    private int currLocation = -1;

    private String activities[] =
            new String[]{"Work", "Code", "Sleep", "Travel", "Food", "Social", "Bathe"};

    private String locations[] =
            new String[]{"Office", "Bedroom", "Transport", "Kitchen", "Living room", "Bathroom"};


    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.frontend);

        final WheelView activity = (WheelView) findViewById(R.id.activity);
        ArrayWheelAdapter<String> activityAdp =
                new ArrayWheelAdapter<String>(this, activities);
        activityAdp.setTextSize(18);
        activity.setViewAdapter(activityAdp);
        activity.setVisibleItems(5);
        activity.setCurrentItem(activities.length/2);

        final WheelView location = (WheelView) findViewById(R.id.location);
        ArrayWheelAdapter<String> locationAdp =
                new ArrayWheelAdapter<String>(this, locations);
        locationAdp.setTextSize(18);
        location.setViewAdapter(locationAdp);
        location.setVisibleItems(5);
        location.setCurrentItem(locations.length/2);


        activity.addChangingListener(new OnWheelChangedListener() {
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                currActivity = newValue;
            }
        });

        location.addChangingListener(new OnWheelChangedListener() {
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                currLocation = newValue;
            }
        });


        final Button button = (Button) findViewById(R.id.start);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String message = "Activity:=" + activities[activity.getCurrentItem()] +
                        "\nLocation:=" + locations[location.getCurrentItem()] +
                        "\nIndexes " + currActivity + " : " + currLocation;
                alert("Started logging!", message);
            }
        });
    }

    /**
     * Show as "OK" dialog.
     */
    protected void alert(String title, String message) {
        new AlertDialog.Builder(this)
                .setMessage(message)
                .setTitle(title)
                .setCancelable(false)
                .setPositiveButton(android.R.string.ok, null)
                .show();
    }

}
